package com.yc.baseapi;

import com.yc.entity.Person;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class TestCollection {
	
	/**
	 * 测试删除集合数据
	 * java.util.ConcurrentModificationException
	 */
	public void testReomveList() {
		List<String> tlist = new ArrayList<>();
		tlist.add("aa");
		tlist.add("bb");
		tlist.add("cc");
		for (String str : tlist) {
			if ("aa".equals(str)) {
				tlist.remove(str);
			}
		}
		for (String s : tlist) {
			System.out.println(s);
		}
	}
	
	public void testIterator() {
		List<String> tlist = new ArrayList<>();
		tlist.add("aa");
		tlist.add("bb");
		tlist.add("cc");
		Iterator<String> at = tlist.iterator(); 
		while(at.hasNext()) {
			String item = at.next();
			if ("bb".equals(item)) {
				at.remove();
			}
		}
		
		for (String s : tlist) {
			System.out.println(s);
		}
		
	}
	
	
	public void testEMPTY_LIST() {
		List<String> aa = Collections.EMPTY_LIST;
		if (aa.isEmpty()) {
			System.out.println("--------------");
		}
	}
	
	public void testIterator2() {
		List<String> tlist = new ArrayList<>();
		tlist.add("aa");
		tlist.add("bb");
		tlist.add("cc");
		Iterator<String> iterator1 = tlist.iterator();
		
		List<String> tlist2 = new ArrayList<>();
		tlist2.add("1");
		tlist2.add("2");
		tlist2.add("3");
		Iterator<String> iterator2 = tlist2.iterator();
		
		while(iterator1.hasNext()) {
			while(iterator2.hasNext()) {
				System.out.println(iterator1.next() + "--" + iterator2.next());
			}
		}
		
	}

	private void testListAddAll() {
		List<String> tlist = new ArrayList<>();
		tlist.add("aa");
		tlist.add("bb");
		tlist.add("cc");

		List<String> tlist2 = new ArrayList<>();
		tlist2.add("aa");
		tlist2.add("cc");
		tlist2.add("ff");

		tlist.addAll(tlist2);
		for (String item : tlist) {
			System.out.println(item);
		}
	}

	private void testConent() {
		List<Person> tlist = new ArrayList<>();
		tlist.add(new Person("a",1));
		tlist.add(new Person("a",2));

		Person p = new Person("b", 1);
		if (!tlist.contains(p)) {
			tlist.contains(p);
		}
		System.out.println(tlist.size());
	}
	

	public static void main(String[] args) {
		TestCollection tc = new TestCollection();
//		tc.testReomveList();
//		tc.testIterator();
//		tc.testEMPTY_LIST();
//		tc.testIterator2();
//		tc.testListAddAll();
		tc.testConent();
	}

}
